package com.kobe.util;

import java.util.ArrayList;
import java.util.List;

public class Perm {
    private static List<int[]> list = new ArrayList<int[]>();

    private static void perm(int[] arr, int k, int m) {
        if (k == m) {
            list.add(arr.clone());
        } else {
            for (int i = k; i <= m; i++) {
                arr[k] = (arr[k] + arr[i]) - (arr[i] = arr[k]);
                perm(arr, k + 1, m);
                arr[k] = (arr[k] + arr[i]) - (arr[i] = arr[k]);
            }
        }
    }

    public static List<int[]> getPerm(int[] arr) {
        perm(arr, 0, arr.length - 1);
        return list;
    }
}
